
// examples/ArgParser/tcp_server.cpp
#include "OA_ArgParser.h"
#include <iostream>
using namespace std;

int main(int argc, const char** argv) {
    OAArgParser ap("tcp_server");
    OpenAPIxx::Args args;
    string errorMessage;
    int ret;

    ap.setArg("--ip", OpenAPIxx::ARGTYPE_STRING, true, "0.0.0.0", "bind ip address", "IP");
    ap.setArg("--port", OpenAPIxx::ARGTYPE_STRING, false, "", "listen port", "PORT");
    ap.setArg("-s", OpenAPIxx::ARGTYPE_FLAG, true, false, "send hello message", "");
    ap.setArg("-w", OpenAPIxx::ARGTYPE_FLAG, true, false, "enable client white list", "");
    ap.setMultiArg({"-W", "--white_list"}, OpenAPIxx::ARGTYPE_STRINGS, true, ARGPARSER_EMPTY_STRS, "client ip white list", "FILE");

    ret = ap.parseArg(argc, argv, args, errorMessage);
    if(ret != 0) {
        cout << errorMessage << endl;
        return 1;
    }

    cout << "[--ip]: " << args["--ip"].strVal << endl;
    cout << "[--port]: " << args["--port"].strVal << endl;
    cout << "[-s]: " << args["-s"].boolVal << endl;
    cout << "[-w]: " << args["-w"].boolVal << endl;
    cout << "[-W]:";
    for(string& fileName : args["-W"].strsVal) {
        cout << " " << fileName;
    }
    cout << endl;
    cout << "[--white_list]:";
    for(string& fileName : args["--white_list"].strsVal) {
        cout << " " << fileName;
    }
    cout << endl;

    return 0;
}